草庐IT

java.lang.ClassCastException : java. lang.String 无法转换为 java.util.Date

全部标签

ruby-on-rails - PostgreSQL gem pg 无法安装

我的数据库是PostgreSQL。我在CENTOS上...。在安装pggem时,我收到以下错误。我也重新安装以清除我的YAML问题,但没有用,但这只是一个警告。我的主要问题是pggem的安装:[root@vdimc04~]#geminstallpg/usr/local/lib/ruby/1.9.1/yaml.rb:56:in`':Itseemsyourrubyinstallationismissingpsych(forYAMLoutput).Toeliminatethiswarning,pleaseinstalllibyamlandreinstallyourruby.Buildingn

ruby - 在 Ruby 中将嵌套哈希键从 CamelCase 转换为 snake_case

我正在尝试构建API包装器gem,但在将哈希键从API返回的JSON转换为更像Rubyish的格式时遇到了问题。JSON包含多层嵌套,包括哈希和数组。我想做的是递归地将所有键转换为snake_case以便于使用。这是我到目前为止所得到的:defconvert_hash_keys(value)returnvalueif(notvalue.is_a?(Array)andnotvalue.is_a?(Hash))result=value.inject({})do|new,(key,value)|new[to_snake_case(key.to_s).to_sym]=convert_hash_

ruby - 如何将字符串数组转换为符号数组?

我想把下面的字符串数组的元素转换成符号,并输出strings=["HTML","CSS","JavaScript","Python","Ruby"]看看我在做什么:strings.each{|x|putsx.to_sym}没有成功。我做错了什么? 最佳答案 使用map而不是each:>>strings.map{|x|x.to_sym}=>[:HTML,:CSS,:JavaScript,:Python,:Ruby]对于Ruby1.8.7及更高版本或包含ActiveSupport,您可以使用以下语法:>>strings.map&:to_

ruby - 安装后无法使用 compass

我似乎无法使用thisVagrantfile使compass在Vagrant上工作.请在此处查看其余的bash脚本(已删除repo)(如果您想配置您的VagrantUbuntuBox,请参阅Vaprobash!)。因此,当我不得不使用gruntserver时,我正在学习gruntjs类(class)。唯一的问题是它需要更新的ruby​​版本(我相信是1.9+而不是1.8)并且它需要compass。所以我通过安装RVM和安装最新的稳定版本解决了ruby​​部分。compass应该很容易获得geminstallcompass并且它似乎确实已安装。但是当我输入compass-v时,我得到了休

ruby-on-rails - 升级到 Yosemite 10.10 后无法连接到 postgresql 数据库

更新到Yosemite10.10后,我无法连接到我的postgresql数据库。我运行Rails控制台并尝试获取第一个用户,但出现此错误...>➜game_golfgit:(master)✗railsc>Loadingdevelopmentenvironment(Rails4.1.4)>[1]pry(main)>User.first>PG::ConnectionBad:couldnotconnecttoserver:Connectionrefused>Istheserverrunningonhost"localhost"(::1)andaccepting>TCP/IPconnectio

ruby - 无法在 Eclipse 4.2 上安装 Aptana 插件

我已经安装了Eclipse4.2Juno。现在我想安装aptana来开发ruby,但是我得到以下错误,Unabletoreadrepositoryathttp://download.aptana.com/studio3/plugin/install/content.jar.无法读取位于http://download.aptana.com/studio3/plugin/install/content.jar的存储库.读取超时 最佳答案 我认为到目前为止您可能已经解决了问题,但我遇到了完全相同的问题并在多次搜索后找到了解决方案,所以为了

ruby-on-rails - 如何在 Ruby 中创建一个新的 Date 实例

如何在给定日期的IRB中创建一个新的日期对象。以下无效。1.9.3p194:053>require'active_support'=>true1.9.3p194:054>Date.new=>#1.9.3p194:055>Date.parse('12/01/2012')NoMethodError:undefinedmethod`parse'forDate:Classfrom(irb):551.9.3p194:055>Date.new('12/01/2012')ArgumentError:wrongnumberofarguments(1for0) 最佳答案

ruby-on-rails - Rails 迁移 : tried to change the type of column from string to integer

我使用railsgeneratemigrations命令在我的rails应用程序中创建了一个表。这是迁移文件:classCreateListings然后我想将纬度和经度存储为整数我试着跑:railsgeneratemigrationchangeColumnType该文件的内容是:classChangeColumnType我原以为列类型会发生变化,但是rake被中止并出现了以下错误消息。我想知道为什么这没有通过?我在我的应用程序中使用postgresql。rakedb:migrate==ChangeColumnType:migrating=========================

ruby-on-rails - 运行 heroku create --stack cedar 时无法加载此类文件 -- readline (LoadError)

我正在尝试将我的Rails应用程序部署到Heroku以按照以下说明进行测试:http://devcenter.heroku.com/articles/rails3#prerequisites这是我要运行的命令:herokucreate--stackcedar我收到此错误消息:/home/sergio/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in`require':cannotloadsuchfile--readline(LoadError)from/home/s

ruby-on-rails - Time.zone.now.to_date 是否等同于 Date.today?

Time.zone.now.to_date是否等同于Date.today?另一种表达方式:Time.zone.now.to_date==Date.today是否始终为true?如果不是,在应用程序时区中获取对应于“现在”的日期对象的最佳方法是什么? 最佳答案 它们并不总是相同的。Time.zone.now.to_date将使用应用程序时区,而Date.today将使用服务器时区。因此,如果两者位于不同的日期,那么它们就会不同。来self的控制台的示例:ruby-1.9.2-p290:036>Time.zone="Sydney"=>"